var events = require('events');
class Downloader extends events.EventEmitter{
    constructor() {
        super();
        this.url = null;
    }
    download_url(path) {
        this.url = path;
        this.emit('start', path);
        setTimeout(()=>{
            this.emit('end', path)
        }, 2000)
    }
}

var d = new Downloader();
d.on('start', (path) => {
    console.log("start downloading:" + path)
});
d.on('end', (path) => {
    console.log("finished:" + path)
});
d.download_url("http://www.baidu.com")